<template>
    <div>
        <el-table :data="list" border style="width: 100%">
            <el-table-column prop="id" label="编号" width="80" align="center">
            </el-table-column>
            <el-table-column prop="name" label="名称" width="120" align="center">
            </el-table-column>
            <el-table-column prop="description" label="描述" align="center">
            </el-table-column>
            <el-table-column prop="type" label="是否启用" width="170" align="center">
                <template slot-scope="scope">
                    <el-switch v-model="scope.row.type" active-text="启用" inactive-text="停用">
                    </el-switch>
                </template>
            </el-table-column>
            <el-table-column prop="action" label="描述操作" width="220" align="center">
                <template slot-scope="scope">
                    <el-button type="text" size="small" icon="el-icon-edit" @click="editbefore(scope.row)">编辑</el-button>
                    <el-button type="text" size="small" icon="el-icon-delete" @click="delbefore(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="block" v-show="pageData.total > pageData.page_size">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="pageData.page" :page-sizes="[5, 8]" :page-size="pageData.page_size"
                layout="total, sizes, prev, pager, next, jumper" :total="pageData.total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
export default {
    name: 'ZdpzList',
    props: {
        list: {
            type: Array,
            default: () => []
        },
        pageData: {
            type: Object,
            default: () => { }
        },
        requestUrl: {
            type: String,
            default: ''
        },
        currentTab: {
            type: String,
            default: ''
        }
    },
    methods: {
        handleCurrentChange(v) {
            this.$emit('pageChange', v)
        },
        handleSizeChange(v) {
            this.$emit('pageSizeChange', v)
        },
        editbefore(v) {
            // this.dialogFormVisible1 = true
            this.$emit('edit', v)
            // this.form1 = {
            //     name: v.name,
            //     description: v.description,
            //     type: String(v.type)
            // }
            // this.editid = v.id
            console.log(v);
        },
        delbefore(v){
            this.$axios({
                url: `${this.requestUrl}${this.currentTab}/${v.id}`,
                method: 'delete',
            })
            this.$emit('addSuccess')
            console.log(v.id);
            console.log(this.requestUrl);
            console.log(this.currentTab);
        }
    }
}
</script>
